package com.chentf.rabbitmq.workquene02;

import com.chentf.rabbitmq.utils.RabbitMqUtilsSGG;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 这是一个工作线程，相当于之前的消费者
 */
public class Worker01 {

    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtilsSGG.getChannel();
        //消息接受
        DeliverCallback deliverCallback = (consumerTag,delivery) -> {
            String receivedMessage = new String(delivery.getBody());
            System.out.println("接受到消息："+receivedMessage);
        };
        //消息被取消
        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println(consumerTag+"消费者取消消息接口回调逻辑");
        };
        System.out.println("C2 消费者启动等待消费...");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
